<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
  <!--请假记录-->
  <meta charset="UTF-8">
  <title>根据id获取的详细信息放到这里</title>
  <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<form method="post" class="layui-form" action="">
  <table class="layui-table">
    <tr class="">
      <th>员工姓名</th>
      <th>请假内容</th>
      <th>开始时间</th>
      <th>结束时间</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
    <tr th:each="e:${listin}">
      <input type="hidden" name="id" th:value="${e.id }">
      <td th:text="${e.empbyname}"></td>
      <input type="hidden" name="empid" th:value="${e.empid }">
      <td th:text="${e.leavetext }"></td>
      <td th:value="${e.leavedate1 }" th:text="${e.leavedate1}"></td>
      <td th:value="${e.leavedate2 }" th:text="${e.leavedate2}"></td>
      <input type="hidden" name="leavedate1" th:value="${e.leavedate1 }">
      <input type="hidden" name="leavedate2" th:value="${e.leavedate2 }">
      <td th:value="${e.statebyname}" th:text="${e.statebyname}"></td>
      <input type="hidden" name="pempid" th:value="${session.loginUser.getEmpId()}">
      <td th:if="${e.leavestate==8}"><button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">同意</button></td>
      <td th:if="${e.leavestate!=8}"><button class="layui-btn layui-btn-normal" disabled="true" style="background-color:#808080">已完成</button></td>
    </tr>
  </table>
</form>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
  layui.use(['form', 'table'], function () {
    var $ = layui.jquery;
    var form = layui.form;
    var layer = layui.layer;

    form.on('submit(saveBtn)', function (data) {
      //console.log(data);
      var tr = $(this).parents("tr");
      let id = $(tr).children("[name='id']").val();
      let empid = $(tr).children("[name='empid']").val();
      let leavedate1 = $(tr).children("[name='leavedate1']").val();
      let leavedate2 = $(tr).children("[name='leavedate2']").val();
      let pempid = $(tr).children("[name='pempid']").val();
      var obj = {
        id : id,
        empid:empid,
        leavedate1:leavedate1,
        leavedate2:leavedate2,
        pempid:pempid,
      }
      $.post('/attendance/approval',obj,function(res){
        if(res.data==="success"){
          var iframeIndex = parent.layer.getFrameIndex(window.name);
          parent.layer.close(iframeIndex);
          //通过父页面去重新加载表格
          parent.layui.table.reload('table-user');
          parent.layer.msg(res.msg);
          this.close();
        }
      })
      return false;
    });

  });
</script>
</body>
</html>